/*
What Are You Talking About
你说的是什么？
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 15929    Accepted Submission(s): 5163


Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. 
伊格内修斯很幸运,他昨天遇到了一个火星人。但他不知道火星人用的语言。
The Martian gives him a history book of Mars and a dictionary when it leaves. 
当他离开时，火星人给了他一本历史书和一本字典。
Now Ignatius want to translate the history book into English. Can you help him?
 现在伊格内修斯想把历史书翻译成英语。你能帮助他吗？

Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. 
这个问题只有一个测试用例，测试用例由两部分组成，字典和书。
The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, 
字典部分的起始行包含一个字符串 "START"（开始），这个字符串应该被忽略，接下来的每一行，都包含两个字符串。
the first one is a word in English, the second one is the corresponding word in Martian's language. 
第一个是一个英文单词，第二个单词是与之匹配的火星文，
A line with a single string "END" indicates the end of the directory part, and this string should be ignored. 
如果有一行是"END"，那么表示字典部分结束了，这一行应该被忽略。
The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. 
书的那部分，第一行是以"START"字符串开始的，这一行应该被忽略，那后是一篇用火星语写的文章。
You should translate the article into English with the dictionary.
你因该用字典吧火星语翻译成英语。
If you find the word in the dictionary you should translate it and write the new word into your translation, 
如果你在字典中找到了这个火星词，那么用英语代替火星词；
if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. 
如果在字典中找不到这个词，那么不需要修改他。
Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. 
空格，制表符，换行符和所有的标点符号都不需要修改。
A line with a single string "END" indicates the end of the book part, and that's also the end of the input.
"END"表示书的部分结束，也代表整个输入结束。
 All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
 所有单词都是用小写，每一个单词最长也只有十个字符，每一行最多有3000个字符。

Output
In this problem, you have to output the translation of the history book.
 这个题目，你应该把历史书翻译成英语。

Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
 

Sample Output
hello, i'm from mars.
i like earth!
-------------------------------------
线性检索耗时大
提交结果：超时
 */
package com.yuan.algorithms.team20150724;

import java.util.Scanner;

public class 线性检索_火星文翻译为英文 {

	static int MAXN = 1000000;
	static String[] result = new String[MAXN];
	static String[] data = new String[MAXN];
	//static String[] book = new String[3005];
	static int tic = 0;// 字典单词数
	static int line = 0;// 文章行数

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		xh : while (sc.hasNext()) {
			empty(result);
			empty(data);
			//empty(book);
			tic = line = 0;
			String in = sc.next();
			if (in.equals("START")) {
				for (int i = 0; true; i++) {
					String t = sc.next();
					if (t.equals("END")) {
						break;
					}
					String t2 = sc.next();
					result[i] = t;
					data[i] = t2;
					tic++;
				}
			}
			String in2 = sc.next();
			sc.nextLine();
			if (in2.equals("START")) {
				for (int i = 0; true; i++) {
					String t = sc.nextLine();
					if (t.equals("END")) {
						break xh;
					}
					output(t);
					// book[i] = t;
					// line++;
				}
			}

		}
	}

	private static void output(String t) {
		String str = t;
		String word = "";
		for (int j = 0; j < str.length(); j++) {
			char temp = str.charAt(j);
			if (temp >= 'a' && temp <= 'z') {
				word += temp;
				// 文章结束，翻译最后一个单词
				if (j == str.length() - 1) {
					System.out.print(query(word));
				}
			} else {
				System.out.print(query(word));
				System.out.print(temp);
				word = "";
			}
		}
		System.out.println();
	}

	private static String query(String word) {
		String t = word;
		for (int i = 0; i < tic; i++) {
			if (data[i].equals(word)) {
				t = result[i];
				return t;
			}
		}
		return t;
	}

	private static void empty(String[] arr) {
		for (int i = 0; i < tic; i++) {
			arr[i] = "";
		}
	}

}
